package com.zhisland.base.support.sys.interceptor;

import com.zhisland.base.support.common.anotation.EnablePaging;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.Method;

/**
 * 作者: guo yao
 * 日期: 2016年02月24日
 * 时间: 下午13:13
 */
@Component
public class MvcPageMethodAdvisor extends AbstractPointcutAdvisor {

    @Resource
    private PagingInterceptor pagingInterceptor;

    private final StaticMethodMatcherPointcut pointcut = new
            StaticMethodMatcherPointcut() {
                @Override
                public boolean matches(Method method, Class<?> targetClass) {
                    return method.isAnnotationPresent(EnablePaging.class);
                }
            };

    @Override
    public Pointcut getPointcut() {
        return this.pointcut;
    }

    @Override
    public Advice getAdvice() {
        return this.pagingInterceptor;
    }
}
